using System;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;

namespace OracleInternal.NotificationServices
{
	internal class PropertyList
	{
		internal PropertyElement head;

		internal int numelems;

		internal PropertyList(int n, InputBuffer ibuf)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)2097408, OracleTraceClassName.PropertyList, OracleTraceFuncName.ctor);
			}
			try
			{
				numelems = 0;
				head = null;
				for (int i = 0; i < n; i++)
				{
					string nextString = ibuf.NextString;
					int num = nextString.IndexOf(':');
					string name = nextString.Substring(0, num);
					string value_Renamed = nextString.Substring(num + 2);
					put(name, value_Renamed);
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)270532608, OracleTraceClassName.PropertyList, OracleTraceFuncName.ctor, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)2097664, OracleTraceClassName.PropertyList, OracleTraceFuncName.ctor);
				}
			}
		}

		protected internal virtual void put(string name, string value_Renamed)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)2097408, OracleTraceClassName.PropertyList, OracleTraceFuncName.put);
			}
			try
			{
				PropertyElement propertyElement = new PropertyElement(name, value_Renamed);
				if (head == null)
				{
					head = propertyElement;
				}
				else
				{
					propertyElement.next = head;
					head = propertyElement;
				}
				numelems++;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)270532608, OracleTraceClassName.PropertyList, OracleTraceFuncName.put, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)2097664, OracleTraceClassName.PropertyList, OracleTraceFuncName.put);
				}
			}
		}

		internal virtual void write(OutputBuffer obuf)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)2097408, OracleTraceClassName.PropertyList, OracleTraceFuncName.write);
			}
			try
			{
				for (PropertyElement next = head; next != null; next = next.next)
				{
					obuf.putString(next.name);
					obuf.putBytes(Notification.headerseparator, 2);
					obuf.putString(next.value_Renamed);
					obuf.putBytes(Notification.crlf, 2);
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)270532608, OracleTraceClassName.PropertyList, OracleTraceFuncName.write, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)2097664, OracleTraceClassName.PropertyList, OracleTraceFuncName.write);
				}
			}
		}

		internal virtual int num()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)2097408, OracleTraceClassName.PropertyList, OracleTraceFuncName.num);
			}
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)2097664, OracleTraceClassName.PropertyList, OracleTraceFuncName.num);
			}
			return numelems;
		}
	}
}
